$().ready(function(){
	init();
})
function init(){
$(".textarea").val("");
	$(".send-msg").click(function(){
		popUpLoadUrl("发消息",'sendMessage',{"act":"sendMessage"},function(){
			$(".pop-submit").click(function(){
				//alert(123);
				var content=$("#send_message").val();
				var title="站内短信";
				if(content){
					$.ajax({type:"POST",
							dataType:"json",
								data:{
										"dataFromType":"ajax",
										enews:"AddMsg",
										title:title,
										"msgtext":content,
										"to_username":($("#username").val())
									},
								url:"../../enews/index.php",
						success:function(r){
							if(r.flag==1){									
								showPopupMsg("成功发送");			
								$("#send_message").val('');
								return false;
							}else if(r.msg){
								alert(r.msg);	
							}
								}});
					return true;
					
				}else{
					alert("内容不能为空");
					$("#send_message").focus();
					return false;
				}

			})
			$(".pop-canel").click(function(){
				popup_close();
			});
			
		});
		return false;
	});
	

	listUserNews("news_1");
}
/**
**设置标签
**
**/
function setMyTags(){
	$("#settag").show();
	//$(".tag>.r").click(function(){
		$("#settag>.btn>input").eq(0).click(function(){
			var checked=[];
			$(".checkbox").each(function(){
				if($(this).attr('checked')){
					checked.push($(this).val());
				}
			});
		
			if(checked.length>5){
				alert("最多只能设置5个标签！");
				return false;
			}else{				
				$.ajax({type:"POST",
							dataType:"json",
								data:{
										"dataFromType":"ajax",
										enews:"editTags",										
										"tags":checked.toString()										
									},
								url:"../../enews/index.php",
						success:function(r){
							if(r.flag==1){									
								//showPopupMsg("成功发送");			
								//$("#send_message").val('');
								//alert('');
								$(".tag>span").eq(0).html(checked.toString());
								$("#settag").fadeOut();
								listUserNews("news_1");
								return false;
							}else if(r.msg){
								alert(r.msg);	
							}
								}});
					return true;
			}
			$(".tag>span").html(checked.toString());
		})
		$("#settag>.btn>input").eq(1).click(function(){			
			$("#settag").fadeOut();
		})
}
function setMyOnLineSay(){
	var word=$(".textarea").val();
		$.ajax({type:"POST",
							dataType:"json",
								data:{
										"dataFromType":"ajax",
										enews:"addOnLineSay",										
										"text":word										
									},
								url:"../../enews/index.php",
						success:function(r){
							if(r.flag==1){
								onLineSayMsg('发布成功!');
								$(".textarea").val("");
								listUserNews("news_1");
								return false;
							}else if(r.msg){
								onLineSayMsg(r.msg);
								return false;
							}
								}});
}
function listUserNews(id){
	var uid=$("#user_id").val();
	var type=$("#"+id).attr("type_id");
	var is_my=$("#is_my").val();
	type=type||"";
	$(".news>a").removeClass("active");
	$("#"+id).addClass("active");
	$("#commentlist>ul").load("../userNews/?uid="+uid+"&is_my="+is_my+"&type_id="+type+"&r="+parseInt(Math.random()*100000),function(){
									
								});
}
/**关注某人*/
function focusUser(_this){
	var tobj=$(".focus_user");
	var tuid=tobj.attr("uid");
	var is_focus=tobj.attr("isfocus");
	$.ajax({type:"POST",
							dataType:"json",
							data:{
									"dataFromType":"ajax",
									enews:"addFocusUser",
									tuid:tuid,
									is_focus:is_focus
									},
							url:"../../enews/index.php",
						success:function(r){
							if(r.flag==1){
								var tobj=$(".focus_user");
								if(is_focus==1){
									tobj.html("关注TA");
									tobj.attr("isfocus",0);
									showPopupMsg("取消成功！");	
								}else{
									tobj.html("取消关注");
									tobj.attr('isfocus',1);
									showPopupMsg("关注成功！");	
								}															
								return false;
							}else if(r.msg){
								showPopupMsg(r.msg);	
							}else{
								alert('系统错误！');
							}
						}});
}
function setWordLimit(){
	var word=$(".textarea").val();
	var length=word.length;	
	var leftLength=140-length;
	if(leftLength>0){
		$(".wordlimit").html(leftLength);
	}else{
		$(".wordlimit").html(0);
		$(".textarea").val((word||"").substring(0,140))
			onLineSayMsg("请输入140个字以内的汉字！");
	}
	return true;

}
function addsay(){
	
}
function onLineSayMsg(text){
	alert(text);
}
